#include "cpu/exec/helper.h"

make_helper(seta) {
	int len = 1 + decode_rm_b(eip + 1);
	uint8_t temp = (cpu.CF == 0 && cpu.ZF == 0);
	write_operand_b(op_src, temp);

	print_asm("seta %s", op_src->str);
	return len;
}

make_helper(setae) {
	int len = 1 + decode_rm_b(eip + 1);
	uint8_t temp = (cpu.CF == 0);
	write_operand_b(op_src, temp);

	print_asm("setae %s", op_src->str);
	return len;
}

make_helper(setb) {
	int len = 1 + decode_rm_b(eip + 1);
	uint8_t temp = (cpu.CF == 1);
	write_operand_b(op_src, temp);

	print_asm("setb %s", op_src->str);
	return len;
}

make_helper(setbe) {
	int len = 1 + decode_rm_b(eip + 1);
	uint8_t temp = (cpu.CF == 1 || cpu.ZF == 1);
	write_operand_b(op_src, temp);

	print_asm("setbe %s", op_src->str);
	return len;
}

make_helper(sete) {
	int len = 1 + decode_rm_b(eip + 1);
	uint8_t temp = (cpu.ZF == 1);
	write_operand_b(op_src, temp);

	print_asm("sete %s", op_src->str);
	return len;
}

make_helper(setg) {
	int len = 1 + decode_rm_b(eip + 1);
	uint8_t temp = (cpu.ZF == 0 && cpu.SF == cpu.OF);
	write_operand_b(op_src, temp);

	print_asm("setg %s", op_src->str);
	return len;
}

make_helper(setge) {
	int len = 1 + decode_rm_b(eip + 1);
	uint8_t temp = (cpu.SF == cpu.OF);
	write_operand_b(op_src, temp);

	print_asm("setge %s", op_src->str);
	return len;
}

make_helper(setl) {
	int len = 1 + decode_rm_b(eip + 1);
	uint8_t temp = (cpu.SF != cpu.OF);
	write_operand_b(op_src, temp);

	print_asm("setl %s", op_src->str);
	return len;
}

make_helper(setle) {
	int len = 1 + decode_rm_b(eip + 1);
	uint8_t temp = (cpu.ZF == 1 || cpu.SF != cpu.OF);
	write_operand_b(op_src, temp);

	print_asm("setle %s", op_src->str);
	return len;
}

make_helper(setne) {
	int len = 1 + decode_rm_b(eip + 1);
	uint8_t temp = (cpu.ZF == 0);
	write_operand_b(op_src, temp);

	print_asm("setne %s", op_src->str);
	return len;
}

make_helper(setno) {
	int len = 1 + decode_rm_b(eip + 1);
	uint8_t temp = (cpu.OF == 0);
	write_operand_b(op_src, temp);

	print_asm("setno %s", op_src->str);
	return len;
}

make_helper(setnp) {
	int len = 1 + decode_rm_b(eip + 1);
	uint8_t temp = (cpu.PF == 0);
	write_operand_b(op_src, temp);

	print_asm("setnp %s", op_src->str);
	return len;
}

make_helper(setns) {
	int len = 1 + decode_rm_b(eip + 1);
	uint8_t temp = (cpu.SF == 0);
	write_operand_b(op_src, temp);

	print_asm("setns %s", op_src->str);
	return len;
}

make_helper(seto) {
	int len = 1 + decode_rm_b(eip + 1);
	uint8_t temp = (cpu.OF == 1);
	write_operand_b(op_src, temp);

	print_asm("seto %s", op_src->str);
	return len;
}

make_helper(setp) {
	int len = 1 + decode_rm_b(eip + 1);
	uint8_t temp = (cpu.PF == 1);
	write_operand_b(op_src, temp);

	print_asm("setp %s", op_src->str);
	return len;
}

make_helper(sets) {
	int len = 1 + decode_rm_b(eip + 1);
	uint8_t temp = (cpu.SF == 1);
	write_operand_b(op_src, temp);

	print_asm("sets %s", op_src->str);
	return len;
}
